﻿#include "gofgame/jumpdown/layer/MenuLayer.h"
#include "gofgame/jumpdown/Scene.h"
#include "gofgame/common/Ref.h"
#include "gofgame/jumpdown/util/objective-c.h"
#include "gofgame/jumpdown/ListScene.h"
#include "gofgame/jumpdown/SettingScene.h"
#include "gofgame/jumpdown/ad/CCAdView.h"

using namespace gofgame::jumpdown::layer;
using namespace gofgame::common;
using namespace gofgame::jumpdown::util;
using namespace cocos2d;


bool MenuLayer::init(){
	CCLayer::init();
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	CCSprite* bg = CCSprite::create("mainBg.png");
	bg->setPosition(ccp(winSize.width /2,winSize.height /2));

	CCMenuItemImage* quickGameMneu = CCMenuItemImage::create("quickgame1.png","quickgame2.png",this,menu_selector(MenuLayer::doQuickGameCallBack));
	CCMenuItemImage* listMenu = CCMenuItemImage::create("list1.png","list2.png",this,menu_selector(MenuLayer::doListCallBack));
	CCMenuItemImage* settingMenu = CCMenuItemImage::create("setting1.png","setting2.png",this,menu_selector(MenuLayer::doSettingCallBack));
	CCMenuItemImage* exitMenu = CCMenuItemImage::create("exit1.png","exit2.png",this,menu_selector(MenuLayer::doExitCallBack));
	CCMenuItemImage *helpMenu = CCMenuItemImage::create("help.png","help.png",this,menu_selector(MenuLayer::doHelpCallBack));
	helpMenu->setScale(0.7f);
	CCMenu* mainMenu = CCMenu::create(quickGameMneu, listMenu, settingMenu, exitMenu,helpMenu,nullptr);
	mainMenu->alignItemsVerticallyWithPadding(20.0f);
	mainMenu->setPosition(ccp(winSize.width /2,winSize.height /2 - 80));
	
	this->addChild(bg);
	this->addChild(mainMenu);

	CCAdView* adView = CCAdView::create(kCCAdSizeSmartBanner, "a1515934afcb350");
	this->addChild(adView, 5);
	adView->loadAd();
	adView->setAlignment(kCCHorizontalAlignmentCenter,kCCVerticalAlignmentBottom);
	adView->setVisible(true);

	return true;
}

MenuLayer *MenuLayer::createMenuLayer() {
	MenuLayer *obj = new MenuLayer();
	obj->init();
	obj->autorelease();
	return obj;
}

void MenuLayer::doQuickGameCallBack(CCObject* pSender){
	Ref<Scene> scene;
	oc_new<Scene>(&scene);
	CCDirector::sharedDirector()->pushScene(scene);
}

void MenuLayer::doListCallBack(CCObject* pSender){
	ListScene* ls = ListScene::createListScene();
	CCDirector::sharedDirector()->pushScene(ls);	
}

void MenuLayer::doExitCallBack(CCObject* pSender){
	CCDirector::sharedDirector()->end();
} 

void MenuLayer::doSettingCallBack(CCObject *pSender){
	SettingScene* ss = SettingScene::createSettingScene();
	CCDirector::sharedDirector()->pushScene(ss);
}

void MenuLayer::doHelpCallBack(CCObject *pSender){
	CCMessageBox("玩家控制角色使用重力感应左右摇动手机游戏。尽量让角色下到更深的层次。您还可以上传您的分数和大家对比哦。如有有意见和问题请加QQ群：181750221。退出游戏请先到主菜单界面。","帮助");
}